<template>
<div class="main">
	<content_top title="权限组管理"></content_top>
	
	<div class="g_box">
		<div class="g_head">
			<h3>数据列表</h3>
			<div class="g_box_right">
				<ButtonGroup class="g_act_box">
					<Button @click="add">新增</Button>
				</ButtonGroup>
			</div>
		</div>
		<div class="g_box_con">
			<Table :columns="Columns" :data="list" style="width: 100%;" border >
				<div slot="footer" style="border-top: 1px solid #eee;padding: 0 10px; text-align: right;    font-size: 14px;">
					
					<div style="float:right;">
						<Page :total="count" show-elevator show-total @on-change="goto_page" />
					</div>
				</div>
			</Table>
		</div>
	</div>
	
	<info_box v-model="einfo.show" :cinfo="einfo.info" @success="success_info"></info_box>
</div>
</template>

<script>
import info_box from './info';

export default {
    data () {
		var self = this;
        return {
			einfo:{
				show:false,
				info:{
					
				}
			},
            Columns: [
				{
					title: '权限组名称',
					key: 'name',
					align: 'center',
                    width: 100
                },
				{
                    title: '职能描述',
					key: 'info',
					
                },
				{
                    title: '成员数量',
					key: 'num',
					width: 150,
                },
				{
                    title: '添加时间',
					key: 'addtime',
					width: 150,
                },
				{
                    title: '是否启用',
					key: 'module',
					width: 150,
					render: (h, params) => {
						return h('i-switch',{
							props:{
								'true-value':1,
								'false-value':0,
								value:parseInt(params.row.is_enable)
							},
							on:{
								'on-change':function(val){
									
									self.set_enable(params.row.id,val);
								}
							}
						});
					}
                },
				{
                    title: '操作',
					key: 'msg',
					width: 250,
					render: (h, params) => {
						return h('div', [
							h('Button', {
								props: {
									type: 'info',
									size: 'small',
								},
								style: {
									marginRight: '5px',
								},
								on: {
									click: () => {
										self.$router.push({name:'r_role_edit',params:{id:params.row.id}});
									}
								}
							}, '权限设置'),
							h('Button', {
								props: {
									type: 'info',
									size: 'small',
								},
								style: {
									marginRight: '5px',
								},
								on: {
									click: () => {
										this.dbedit(params.row)
									}
								}
							}, '编辑'),
							h('Button', {
								props: {
									type: 'info',
									size: 'small',
								},
								style: {
									
								},
								on: {
									click: () => {
										self.remove(params.row.id)
									}
								}
							}, '删除')
						]);
					}
                },
            ],
			list:[],
			page:1,
			count:0,
			filter:{
				
			}
        };
    },
	components:{
		info_box
	},
	created(){
		this.load_data();
	},
    methods: {
		load_data(){
			var self = this;
			var postdata = {
				page:this.page,
				f:this.filter
			};
			Whttp.load('System/Privgroup/get_list',postdata,function(result){
				self.list = result.list;
				self.count = parseInt(result.count);
			});
		},
		goto_page(page){
			this.page = page;
			this.load_data();
		},
		query(){
			this.page = 1;
			this.load_data();
		},
		date_change(dates){
			this.filter.start_time = dates[0];
			this.filter.end_time = dates[1];
		},
		add(){
			this.einfo.show = true;
			this.einfo.info = {};
		},
		dbedit(row){
			this.einfo.info = row;
			this.einfo.show = true;
		},
		success_info(res){
			this.page = 1;
			this.load_data();
		},
		set_enable(id,status){
			var self = this;
			var postdata = {
				id:id,
				status:status
			};
			Whttp.load('System/Privgroup/set_enable',postdata,function(result){
				self.$Message.info('操作成功');
			});
		},
		remove(id){
			var self = this;
			if(!confirm('是否删除')){
				return false;
			}
			var postdata = {
				id:id
			};
			Whttp.load('System/Privgroup/del',postdata,function(result){
				self.load_data();
				self.$Message.info('删除成功');
			});
		},
    }
};
</script>

